package com.ganbo.ms.controller;

import com.ganbo.ms.config.TestConfig;
import com.ganbo.ms.pool.TestObject;
import com.ganbo.ms.pool.TestObjectPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class TestController {

    @Autowired
    private TestObjectPool testObjectPool;

    @Autowired
    @Lazy
    TestConfig testConfig;

    @GetMapping("/poolTest")
    public String test() {
        TestObject testObject = null;
        try {
            testObject = testObjectPool.borrowObject();
            //省略业务代码...

            System.out.println("===============>" + testConfig);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (testObject != null) {
                //最终归还对象到对象池
                testObjectPool.returnObject(testObject);
            }
        }
        return "success";
    }

}

